/*
 * DiaryListAdapter.java
 * classes : com.ruint.master.adapter.DiaryListAdapter
 * @author ruint
 * V 1.0.0
 * Create at 2014-12-2 下午1:13:35
 */
package com.ruint.master.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ruint.core.adapter.BaseRefreshListAdapter;
import com.ruint.core.utils.DateUtils;
import com.ruint.core.utils.ViewHolder;
import com.ruint.core.utils.bitmap.ImageLoaderUtils;
import com.ruint.lib.pulltorefresh.library.PullToRefreshListView;
import com.ruint.master.R;
import com.ruint.master.bean.Diary;

/**
 * com.ruint.master.adapter.DiaryListAdapter
 * 
 * @author ruint <br/>
 *         create at 2014-12-2 下午1:13:35
 */
public class DiaryListAdapter extends BaseRefreshListAdapter<Diary, PullToRefreshListView> {

  /**
   * @param context
   */
  public DiaryListAdapter(Context context, PullToRefreshListView listView) {
    super(context, listView);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = LayoutInflater.from(context).inflate(R.layout.diary_list_item_other, null);
    }
    ImageView avatar_other = ViewHolder.get(convertView, R.id.diary_avatar);
    TextView username_other = ViewHolder.get(convertView, R.id.diary_username);
    TextView time_other = ViewHolder.get(convertView, R.id.diary_time);
    TextView title_other = ViewHolder.get(convertView, R.id.diary_title);
    TextView views_other = ViewHolder.get(convertView, R.id.diary_views);
    TextView reply_other = ViewHolder.get(convertView, R.id.diary_reply);

    final Diary bean_other = mList.get(position);

    if (bean_other != null) {
      ImageLoaderUtils.getInstance().displayImage(bean_other.getD_author_avatar(), avatar_other, R.drawable.wait);
      username_other.setText(bean_other.getD_author_name());
      if (bean_other.getDr_time() != null) {
        time_other.setText(DateUtils.getDiaryTime(bean_other.getDr_time()));
      } else {
        time_other.setText(DateUtils.getDiaryTime(bean_other.getD_addtime()));
      }
      title_other.setText(bean_other.getD_subject());
      views_other.setText(bean_other.getD_views());
      reply_other.setText(bean_other.getD_replies());
    }
    return convertView;
  }
}